package com.lam.common.config;

import javax.servlet.Filter;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.lam.framework.datasource.config.LamDruidStat;
import com.lam.framework.datasource.model.LamDruidStatProperties;

/**
 * druid 配置多数据源
 * 
 * @author lam
 */
@Configuration
public class DruidStatConfig extends LamDruidStat{

	@Bean("masterDruidPro")
	@ConditionalOnProperty(name = "datasource.master.statViewServlet.enabled", havingValue = "true")
	@ConfigurationProperties("datasource.master")
	public LamDruidStatProperties masterDruidStatProperties() {
		return new LamDruidStatProperties();
	}
	
//	@Bean("slaveDruidPro")
//	@ConditionalOnProperty(name = "datasource.slave.statViewServlet.enabled", havingValue = "true")
//	@ConfigurationProperties("datasource.slave")
//	public LamDruidStatProperties slaveDruidStatProperties() {
//		return new LamDruidStatProperties();
//	}
	
	/**
	 * 去除监控页面底部的广告
	 */
	@Bean
	@ConditionalOnProperty(name = "datasource.master.statViewServlet.enabled", havingValue = "true")
	public FilterRegistrationBean<Filter> removeMasterDruidFilterAD(@Qualifier("masterDruidPro")LamDruidStatProperties masterDruidPro) {
		return removePageAD("masterDruidStat", masterDruidPro);
	}
	
	/**
	 * 去除监控页面底部的广告
	 */
//	@Bean
//	@ConditionalOnProperty(name = "datasource.slave.statViewServlet.enabled", havingValue = "true")
//	public FilterRegistrationBean<Filter> removeSlaveDruidFilterRegistrationBean(@Qualifier("slaveDruidPro")LamDruidStatProperties slaveDruidPro) {
//		return removePageAD("slaveDruidStat", slaveDruidPro);
//	}
	
}
